package com.example.demo.controller;

import com.example.demo.model.MessageInfo;
import com.example.demo.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RequestMapping("/messageInfo")
@RestController
public class MessageInfoController {
    @Autowired
    private MessageInfoService messageInfoService;

    @RequestMapping("/publish")
    public boolean addMessage(MessageInfo messageInfo) {
        if(!StringUtils.hasLength(messageInfo.getMessage())
        ||!StringUtils.hasLength(messageInfo.getFrom())
        ||!StringUtils.hasLength(messageInfo.getTo())) {
            return false;
        }
        messageInfoService.insertMessageInfo(messageInfo);
        return true;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getAllMessageInfo() {
        return messageInfoService.selectAllMessage();
    }


}
